package com.txunda.zhuohired.aty.manage.home;

import android.os.Bundle;
import android.support.annotation.IdRes;
import android.support.v4.app.Fragment;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.ants.theantsgo.config.Config;
import com.flyco.tablayout.utils.FragmentChangeManager;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.txunda.zhuohired.R;
import com.txunda.zhuohired.base.BaseAty;
import com.txunda.zhuohired.fgt.manage.ManageHomeFgt;
import com.txunda.zhuohired.fgt.manage.ManageMyFgt;
import com.txunda.zhuohired.fgt.manage.ManageNewsFgt;

import java.util.ArrayList;

/**
 * 创建人： Txd_Cjh
 * 创建时间： 2018/3/10 14:06
 * 功能描述：企业主页
 * 联系方式：jiahuanchen@126.com
 */

public class ManageAty extends BaseAty implements RadioGroup.OnCheckedChangeListener{

    @ViewInject(R.id.rg_manage)
    private RadioGroup rg_manage;
    /**
     * 推荐
     */
    @ViewInject(R.id.rb_manage_home)
    private RadioButton rb_manage_home;
    /**
     * 消息
     */
    @ViewInject(R.id.rb_manage_news)
    private RadioButton rb_manage_news;
    /**
     * 我的
     */
    @ViewInject(R.id.rb_manage_my)
    private RadioButton rb_manage_my;
    private FragmentChangeManager fcm;
    private ArrayList<Fragment> fragments;
    private int checkStatus = 0;
    private ManageHomeFgt manageHomeFgt;
    private ManageNewsFgt manageNewsFgt;
    private ManageMyFgt manageMyFgt;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        rg_manage.setOnCheckedChangeListener(this);
        fcm = new FragmentChangeManager(getSupportFragmentManager(), R.id.fl_manage_home, fragments);
    }


    @Override
    protected int getLayoutResId() {
        return R.layout.aty_manage;
    }

    @Override
    protected void initialized() {
        fragments = new ArrayList<>();
        manageHomeFgt = new ManageHomeFgt();
        manageNewsFgt = new ManageNewsFgt();
        manageMyFgt = new ManageMyFgt();
        fragments.add(manageHomeFgt);
        fragments.add(manageNewsFgt);
        fragments.add(manageMyFgt);
    }

    @Override
    protected void requestData() {

    }
    @Override
    public void onResume() {
        super.onResume();
        if (Config.isLogin()) {// 已登录
            switch (checkStatus) {
                case 0:
                    rb_manage_home.setChecked(true);
                    break;
                case 1:
                    rb_manage_news.setChecked(true);
                    break;
                case 2:
                    rb_manage_my.setChecked(true);
                    break;
            }
        } else {// 未登录
            switch (checkStatus) {
                case 0:
                    rb_manage_home.setChecked(true);
                    break;
                case 1:
                    rb_manage_news.setChecked(true);
                    break;
                case 2:
                    rb_manage_my.setChecked(true);
                    break;
            }
        }
    }

    @Override
    public void onCheckedChanged(RadioGroup radioGroup, @IdRes int i) {
        switch (i) {
            case R.id.rb_manage_home://推荐
                checkStatus = 0;
                fcm.setFragments(0);
                break;
            case R.id.rb_manage_news://消息
                checkStatus = 1;
                fcm.setFragments(1);
                break;
            case R.id.rb_manage_my://我的
                checkStatus = 2;
                fcm.setFragments(2);
                break;
        }
    }
}
